﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.MsNotify;
using Newtonsoft.Json;

namespace Ccit.OA.Notify
{
    public partial class notify_view_reply : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _hidState.Value = "";
                _hidNotiFyId.Value = (null != Request.QueryString["NotiFyId"]) ? Request.QueryString["NotiFyId"].ToString() : "";
                _hidsUserId.Value = (null != Request.QueryString["UserId"]) ? Request.QueryString["UserId"].ToString() : "";
                _hidReceipt.Value = (null != Request.QueryString["Receipt"]) ? Request.QueryString["Receipt"].ToString() : "";
            }
            if (_hidNotiFyId.Value != "")
            {
                InitPage();
            }
        }

        private void InitPage()
        {
            NotifyBLL Bll = new NotifyBLL();
            MsNotifyMessage ms = Bll.GetReplyView(_hidNotiFyId.Value);            
            if(ms!=null)
            {
                lblTitle.Text = (ms.title!="")?ms.title:"&nbsp;";
                lblPerson.Text = (ms.username != "") ? ms.username+"("+ms.deptname+")" : "&nbsp;";
                lblType.Text = (ms.type != "") ? ms.type : "&nbsp;";
                lblTime.Text = (ms.releasetime != "") ? ms.releasetime : "&nbsp;";
                lblImport.Text = (ms.importance != "") ? ms.importance : "&nbsp;";
                freTextInfo.Text = ms.content;
                ucAttach.ViewShow("0020", ms.id);
            }
            string iCount = Bll.GetUserMessage(_hidsUserId.Value, _hidNotiFyId.Value);
            if (iCount != "")
            {
                string[] flowId = iCount.Split(',');
                txtContent.Text = flowId[2].ToString();
                _hidState.Value = flowId[1].ToString(); 
            }
            MsViewClass msView = new MsViewClass();
            msView.state = _hidState.Value;
            msView.Userid = _hidsUserId.Value;
            msView.NotiFyId = _hidNotiFyId.Value;
            string iNum = Bll.DoOperateReplyView(msView);
            if (iNum != "-999")
            {
                _hidState.Value = "1";
            }
            if (_hidReceipt.Value == "1")
            {
                trReplay.Attributes["style"] = "display:block";
                trReplayContent.Attributes["style"] = "display:block";
                trButtonOk.Attributes["style"] = "display:block";
            }
            Bll = null;
        }
        [global::System.Web.Services.WebMethod]
        public static string DoSaveMes(string strJson)
        {
            NotifyBLL Bll = new NotifyBLL();
            MsViewClass ms = (MsViewClass)JavaScriptConvert.DeserializeObject(strJson, typeof(MsViewClass));
            string iNum  = Bll.DoOperateReplyView(ms);            
            Bll = null;
            return iNum;
        }

    }
}
